//
//  XCRankTableViewCell.m
//  SoundOfNature
//
//  Created by 梁新昌 on 16/3/10.
//  Copyright © 2016年 梁新昌. All rights reserved.
//

#import "XCRankTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation XCRankTableViewCell

- (void)dealloc {
    [_picImageView release];
    [_titleLable release];
    [_nameLable release];
    [_moreButton release];
    [_name1Lable release];
    [_name2Lable release];

    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.titleLable = [[XCBaseLable alloc] initWithFrame:CGRectZero];
        self.picImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.nameLable = [[XCBaseLable alloc] initWithFrame:CGRectZero];
        self.name1Lable = [[XCBaseLable alloc] initWithFrame:CGRectZero];
        self.name2Lable = [[XCBaseLable alloc] initWithFrame:CGRectZero];
        self.moreButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.moreButton setImage:[UIImage imageNamed:@"Image-rankMore"] forState:UIControlStateNormal];
        
        
        [self.contentView addSubview:self.name1Lable];
        [self.contentView addSubview:self.name2Lable];
        [self.contentView addSubview:self.moreButton];
        [self.contentView addSubview:self.picImageView];
        [self.contentView addSubview:self.nameLable];
        [self.contentView addSubview:self.titleLable];

        [self.name1Lable release];
        [self.name2Lable release];
        [self.nameLable release];
        [self.titleLable release];
        [self.picImageView release];
    }
    return self;
}
- (void)layoutSubviews {
    self.picImageView.frame = CGRectMake(10, 10, self.bounds.size.width / 3, self.bounds.size.height - 10);
    self.titleLable.frame = CGRectMake(self.picImageView.bounds.size.width + 20, 10, self.bounds.size.width / 3, 21);
    self.titleLable.textColor = [UIColor colorWithWhite:0.200 alpha:1.000];

    if ([UIScreen mainScreen].bounds.size.width > 320) {
        
        self.nameLable.frame = CGRectMake(self.picImageView.bounds.size.width + 20, 30 + self.titleLable.bounds.size.height, self.bounds.size.width / 3, 21);
        self.nameLable.font = [UIFont systemFontOfSize:10];
        
        self.name1Lable.frame = CGRectMake(self.picImageView.bounds.size.width + 20, 52 + self.nameLable.bounds.size.height, self.bounds.size.width / 3, 21);
        self.name1Lable.font = [UIFont systemFontOfSize:10];
        self.name2Lable.frame = CGRectMake(self.picImageView.bounds.size.width + 20, 73 + self.nameLable.bounds.size.height, self.bounds.size.width / 3, 21);
        self.name2Lable.font = [UIFont systemFontOfSize:10];
    } else {
        self.titleLable.font = [UIFont systemFontOfSize:13];
        self.nameLable.frame = CGRectMake(self.picImageView.bounds.size.width + 20, 10 + self.titleLable.bounds.size.height, self.bounds.size.width / 3, 21);
        self.nameLable.font = [UIFont systemFontOfSize:8];
        
        self.name1Lable.frame = CGRectMake(self.picImageView.bounds.size.width + 20, 36 + self.nameLable.bounds.size.height, self.bounds.size.width / 3, 21);
        self.name1Lable.font = [UIFont systemFontOfSize:8];
        self.name2Lable.frame = CGRectMake(self.picImageView.bounds.size.width + 20, 62 + self.nameLable.bounds.size.height, self.bounds.size.width / 3, 21);
        self.name2Lable.font = [UIFont systemFontOfSize:8];
    }
    self.nameLable.textColor = [UIColor colorWithWhite:0.502 alpha:1.000];
    self.name1Lable.textColor = [UIColor colorWithWhite:0.502 alpha:1.000];
    self.name2Lable.textColor = [UIColor colorWithWhite:0.502 alpha:1.000];
    self.moreButton.frame = CGRectMake(self.bounds.size.width - 50, self.bounds.size.height / 2 - 10, 20, 20);
}
- (void)setRefsModel:(XCRefsModel *)refsModel {
    if (_refsModel != refsModel) {
        [_refsModel release];
        _refsModel = [refsModel retain];
    }
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:[refsModel.image objectForKey:@"pic"]]placeholderImage:[UIImage imageNamed:@"Image-p"]];
    
    self.titleLable.text = refsModel.title;

    XCRankSongsModel *songsModel = refsModel.mutableArray[0];
    self.nameLable.text = [NSString stringWithFormat:@"1.%@-%@", songsModel.name, songsModel.singerName];
    XCRankSongsModel *songsModel1 = refsModel.mutableArray[1];
    self.name1Lable.text = [NSString stringWithFormat:@"2.%@-%@", songsModel1.name, songsModel1.singerName];
    XCRankSongsModel *songsModel2 = refsModel.mutableArray[2];
    self.name2Lable.text = [NSString stringWithFormat:@"3.%@-%@", songsModel2.name, songsModel2.singerName];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
